<?php
class penandatangan extends CI_Controller {

	function __construct()
	{
		parent::__construct();
		$this->load->model('mpenandatangan');
	}
	
	function index()
	{
		$token = $this->session->userdata('token');
		if($token){
			$sektor = $this->session->userdata('sektor');
			$data['results'] = $this->mpenandatangan->getList($sektor);
			$data['pihak'] = $this->mpenandatangan->getListPihak($sektor);
			$this->load->view('penandatangan/list',$data);
		}else{
			redirect('login');
		}
	}
    
	function add(){
		$data['mode'] = "tambah";
		$data['action'] = "save";
		$this->load->view('penandatangan/form',$data);
	}
	
	function edit($id_penandatangan){
		$data['mode'] = "ubah";
		$data['action'] = "update";
		$sektor = $this->session->userdata('sektor');
		$data['detail'] = $this->mpenandatangan->detail($id_penandatangan);
		$this->load->view('penandatangan/form',$data);
	}
	
	function addpihaklain(){
		$data['mode'] = "tambah";
		$data['action'] = "save";
		$this->load->view('penandatangan/form_ketiga',$data);
	}
	
	function editpihaklain($id_penandatangan){
		$data['mode'] = "ubah";
		$data['action'] = "update";
		$sektor = $this->session->userdata('sektor');
		$data['detail'] = $this->mpenandatangan->detail($id_penandatangan);
		$this->load->view('penandatangan/form_ketiga',$data);
	}
	
	function save()
	{
		$$id_penandatangan = $this->input->post('id_penandatangan');
		$no_penandatangan = $this->input->post('no_penandatangan');
		$nama_penandatangan = $this->input->post('nama_penandatangan');
		$jabatan_penandatangan = $this->input->post('jabatan_penandatangan');
		$posisi_penandatangan = $this->input->post('posisi_penandatangan');
		$is_disampaikan = $this->input->post('is_disampaikan');
		$id_sektor = $this->input->post('id_sektor');
		
		$submit = $this->input->post('submit');	
		if ($submit)
		{
			$this->mpenandatangan->setData($id_penandatangan,$no_penandatangan,$nama_penandatangan,$jabatan_penandatangan,$posisi_penandatangan,$is_disampaikan,$id_sektor);
			$this->mpenandatangan->create();
			$this->session->set_flashdata('success', true);
			redirect('penandatangan');
		}
		$this->session->set_flashdata('error', true);
		redirect('penandatangan');
	}
	
	function update()
	{
		$id_penandatangan = $this->input->post('id_penandatangan');
		$no_penandatangan = $this->input->post('no_penandatangan');
		$nama_penandatangan = $this->input->post('nama_penandatangan');
		$jabatan_penandatangan = $this->input->post('jabatan_penandatangan');
		$posisi_penandatangan = $this->input->post('posisi_penandatangan');
		$is_disampaikan = $this->input->post('is_disampaikan');
		$id_sektor = $this->input->post('id_sektor');
		
		$submit = $this->input->post('submit');	
		if ($submit)
		{
			$this->mpenandatangan->setData($id_penandatangan,$no_penandatangan,$nama_penandatangan,$jabatan_penandatangan,$posisi_penandatangan,$is_disampaikan,$id_sektor);
			$this->mpenandatangan->update($id_penandatangan);
			$this->session->set_flashdata('success', true);
			redirect('penandatangan');
		}
		$this->session->set_flashdata('error', true);
		redirect('penandatangan');
	}
	
	function delete($id_penandatangan)
	{
		if ($this->mpenandatangan->remove($id_penandatangan)){
			$this->session->set_flashdata('delete', true);
			redirect('penandatangan','refresh');
		}
		$this->session->set_flashdata('error', true);
		redirect('penandatangan');
	}	
	
	function searchData(){
		$name = $this->input->post('name');
		$data['results'] = $this->mpenandatangan->getListSearch($name);
		$this->load->view('penandatangan/list',$data);
	}
}
?>